#!/usr/bin/env python
"""
检查用户密码
"""
import os
import sys
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inter_api.settings')
django.setup()

from django.contrib.auth import get_user_model
from students.models import Student
from resume_management.models import Resume

User = get_user_model()

def check_user_password():
    """检查用户密码"""
    print("检查用户密码...")
    
    try:
        # 获取简历ID=27对应的学生用户
        resume = Resume.objects.get(id=27)
        student = resume.student
        user = student.user
        
        print(f"用户名: {user.username}")
        print(f"邮箱: {user.email}")
        print(f"是否激活: {user.is_active}")
        print(f"角色: {user.role}")
        
        # 尝试设置一个已知的密码
        new_password = 'testpass123'
        user.set_password(new_password)
        user.save()
        
        print(f"✅ 已设置密码为: {new_password}")
        
        # 验证密码
        if user.check_password(new_password):
            print("✅ 密码验证成功")
        else:
            print("❌ 密码验证失败")
            
    except Exception as e:
        print(f"检查失败: {e}")
        import traceback
        traceback.print_exc()

if __name__ == '__main__':
    check_user_password()
